package com.ybwh.springboot2.common.mybatis.plugin.sass;

import org.apache.commons.lang3.StringUtils;

/**
 * @author fanbeibei
 * @version 1.2.0
 * @date 2022/2/19 20:12
 */
public class TenantIdHelper {


    private TenantIdHelper() {
    }


    /**
     * @author fanbeibei
     * @version 1.2.0
     * @date 2022/2/19 19:49
     */
    private static class TenantIdHolder {
        private static ThreadLocal<String> TENANT_ID = new ThreadLocal<>();


        public static String get() {
            return TENANT_ID.get();
        }


        public static void set(String tenantId) {
            TENANT_ID.set(tenantId);

        }

        public static void remove() {
            TENANT_ID.remove();

        }


    }

    public static void clearTenantId() {
        TenantIdHolder.remove();
    }

    public static void setTenantId(String tenantId) {
        TenantIdHolder.set(tenantId);
    }


    public static String getTenantId() {
        String ts = TenantIdHolder.get();

        if (StringUtils.isBlank(ts)) {
            return "";
        }

        return ts;
    }

}
